package utils;

import java.util.Date;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import models.Msgsendlog;
import play.Logger;
import play.db.jpa.JPA;

public class MsgsendlogUtil {
	

	public static void write(Long hashid ,String msgcontent ,Date msgtime 
			,String msgtype ,String orgcode ,String orderno ,String netticketid ,Long msghashid
			,Date dealtime ,boolean dealed ,boolean issendsuccess){
		EntityManager em = JPA.newEntityManager();
		try{
			EntityTransaction transaction = em.getTransaction();
			transaction.begin();
			Msgsendlog log = new Msgsendlog();
			log.hashid = hashid;
			log.msgcontent = msgcontent;
			log.msgtime = msgtime;
			log.msgtype = msgtype;
			log.orgcode = orgcode;
			log.orderno = orderno;
			log.netticketid = netticketid;
			log.msghashid = msghashid;
			log.dealtime = dealtime;
			log.dealed = dealed;
			log.issendsuccess = issendsuccess;
			em.persist(log);
			transaction.commit();
		}catch(Exception e){
			em.getTransaction().rollback();
			Logger.log4j.error("消息日志插入失败 ：   ", e);
		}finally{
			if(em.getTransaction().isActive()){
				em.getTransaction().commit();
			}
			if(em!=null){
				if(em.isOpen()){
					em.close();
				}
			}
		}
	}
}
